package com.yellowpage.omc.ability.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;
import com.yellowpage.omc.ability.data.AppInterfaceParamValue;
import com.yellowpage.omc.ability.service.AppInterfaceParamValueService;

public class AppInterfaceParamValueAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<AppInterfaceParamValue> appInterfaceParamValueList = new ArrayList<AppInterfaceParamValue>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private AppInterfaceParamValue appInterfaceParamValue;
	private AppInterfaceParamValueService appInterfaceParamValueService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_paramValueId;
		private String query_interfaceParamId;
		private String query_paramValueDiaplay;
		private String query_paramValue;
		private String query_note;
		private String query_createUser;
		private String query_createTime;
		private String query_lastUpdateUser;
		private String query_lastUpdateTime;
		private String query_status;
		private String query_LastSynchronizationUser;
		private String query_LastSynchronizationTime;

	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.appInterfaceParamValue = appInterfaceParamValueService.getAppInterfaceParamValue(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("paramValueId", query_paramValueId);
	    	    queryMap.put("interfaceParamId", query_interfaceParamId);
	    	    queryMap.put("paramValueDiaplay", query_paramValueDiaplay);
	    	    queryMap.put("paramValue", query_paramValue);
	    	    queryMap.put("note", query_note);
	    	    queryMap.put("createUser", query_createUser);
	    	    queryMap.put("createTime", query_createTime);
	    	    queryMap.put("lastUpdateUser", query_lastUpdateUser);
	    	    queryMap.put("lastUpdateTime", query_lastUpdateTime);
	    	    queryMap.put("status", query_status);
	    	    
	    	    queryMap.put("LastSynchronizationUser", query_LastSynchronizationUser);
	    		queryMap.put("LastSynchronizationTime", query_LastSynchronizationTime);
	    		
		resultList = appInterfaceParamValueService.queryAppInterfaceParamValueByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		appInterfaceParamValueService.saveAppInterfaceParamValue(appInterfaceParamValue);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    	    	    	    	    if (appInterfaceParamValue.getParamValueDiaplay().length() == 0) {
			this.addActionError("** ParamValueDiaplay 不能为空 !");
		}
			    	    	    if (appInterfaceParamValue.getParamValue().length() == 0) {
			this.addActionError("** ParamValue 不能为空 !");
		}
			    	    	    if (appInterfaceParamValue.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    	    	    	    	    	    	    	    	    	    	    if (appInterfaceParamValue.getStatus().length() == 0) {
			this.addActionError("** Status 不能为空 !");
		}
			    	    
		this.setValidatorResult("/omc/ability/AppInterfaceParamValueAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    appInterfaceParamValue = appInterfaceParamValueService.getAppInterfaceParamValue(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    appInterfaceParamValueService.updateAppInterfaceParamValue(appInterfaceParamValue);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    			    			    if (appInterfaceParamValue.getParamValueDiaplay().length() == 0) {
			this.addActionError("** ParamValueDiaplay 不能为空 !");
		}
			    			    if (appInterfaceParamValue.getParamValue().length() == 0) {
			this.addActionError("** ParamValue 不能为空 !");
		}
			    			    if (appInterfaceParamValue.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    			    			    			    			    			    if (appInterfaceParamValue.getStatus().length() == 0) {
			this.addActionError("** Status 不能为空 !");
		}
			    		this.setValidatorResult("/omc/ability/AppInterfaceParamValueUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.appInterfaceParamValueService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲突，删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setAppInterfaceParamValue(AppInterfaceParamValue appInterfaceParamValue) {
		this.appInterfaceParamValue = appInterfaceParamValue;
	}
	
	public AppInterfaceParamValue getAppInterfaceParamValue() {
		return appInterfaceParamValue;
	}
	 
	 
	 public void setAppInterfaceParamValueService(AppInterfaceParamValueService appInterfaceParamValueService) {
		this.appInterfaceParamValueService = appInterfaceParamValueService;
	}
	
	public List<AppInterfaceParamValue> getAppInterfaceParamValueList() {
		return appInterfaceParamValueList;
	}

	public void setAppInterfaceParamValueList(List<AppInterfaceParamValue> appInterfaceParamValueList) {
		this.appInterfaceParamValueList = appInterfaceParamValueList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_paramValueId() {
        return this.query_paramValueId;
    }
    
    public void setQuery_paramValueId(String paramValueId){
        this.query_paramValueId = paramValueId;
    }    

        public String getQuery_interfaceParamId() {
        return this.query_interfaceParamId;
    }
    
    public void setQuery_interfaceParamId(String interfaceParamId){
        this.query_interfaceParamId = interfaceParamId;
    }    

        public String getQuery_paramValueDiaplay() {
        return this.query_paramValueDiaplay;
    }
    
    public void setQuery_paramValueDiaplay(String paramValueDiaplay){
        this.query_paramValueDiaplay = paramValueDiaplay;
    }    

        public String getQuery_paramValue() {
        return this.query_paramValue;
    }
    
    public void setQuery_paramValue(String paramValue){
        this.query_paramValue = paramValue;
    }    

        public String getQuery_note() {
        return this.query_note;
    }
    
    public void setQuery_note(String note){
        this.query_note = note;
    }    

        public String getQuery_createUser() {
        return this.query_createUser;
    }
    
    public void setQuery_createUser(String createUser){
        this.query_createUser = createUser;
    }    

        public String getQuery_createTime() {
        return this.query_createTime;
    }
    
    public void setQuery_createTime(String createTime){
        this.query_createTime = createTime;
    }    

        public String getQuery_lastUpdateUser() {
        return this.query_lastUpdateUser;
    }
    
    public void setQuery_lastUpdateUser(String lastUpdateUser){
        this.query_lastUpdateUser = lastUpdateUser;
    }    

        public String getQuery_lastUpdateTime() {
        return this.query_lastUpdateTime;
    }
    
    public void setQuery_lastUpdateTime(String lastUpdateTime){
        this.query_lastUpdateTime = lastUpdateTime;
    }    

        public String getQuery_status() {
        return this.query_status;
    }
    
    public void setQuery_status(String status){
        this.query_status = status;
    }    
    /**
	 * @return the query_LastSynchronizationUser
	 */
	public String getQuery_LastSynchronizationUser() {
		return query_LastSynchronizationUser;
	}

	/**
	 * @param query_LastSynchronizationUser the query_LastSynchronizationUser to set
	 */
	public void setQuery_LastSynchronizationUser(
			String query_LastSynchronizationUser) {
		this.query_LastSynchronizationUser = query_LastSynchronizationUser;
	}

	/**
	 * @return the query_LastSynchronizationTime
	 */
	public String getQuery_LastSynchronizationTime() {
		return query_LastSynchronizationTime;
	}

	/**
	 * @param query_LastSynchronizationTime the query_LastSynchronizationTime to set
	 */
	public void setQuery_LastSynchronizationTime(
			String query_LastSynchronizationTime) {
		this.query_LastSynchronizationTime = query_LastSynchronizationTime;
	}
    
	
}
